<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title>系统人员</title>
		<script th:src="@{/layui/layui.js}" type="text/javascript"></script>
		<link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
		<style>
			.layui-elem-quote{
				border-left: 5px solid #1e9fff;
			}
		</style>
	</head>
	<body>
		
		<div class="layui-panel" style="padding: 8px;">
			<blockquote class="layui-elem-quote layui-border-blue">定时任务配置</blockquote>
			<div>
				<table id="quartzTable" lay-filter="quartzTable"></table>
			</div>
		</div>
		<script id="tool" type="text/html">
			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="one">执行一次</a>
			<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="start">启动</a>
			<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="stop">暂停</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
		</script>
		<script id="tableBar" type="text/html">
			<a class="layui-btn layui-btn-normal layui-btn-md" lay-event="add">
				<i class="layui-icon layui-icon-add-1"></i>
				新增任务
			</a>
		</script>
		<script id="swicthState" type="text/html">
			<input type="checkbox" name="state" value="{{d.state}}"
				lay-skin="switch" lay-text="运行中|暂停中" lay-filter="checkState" {{d.state=="ACQUIRED"?"checked":""}} />
		</script>
		<script>
			var data = [
				{"jobName":"hqj123","jobGroup":"hqj23","state":"1","className":"18577896741","triggerName":"QQ:3833491403","triggerGroup":"QQ:3833491403","crateTime":"2021-12-01"}
			]
			var $;
			layui.use(['table','form','jquery'],function(){
				var table = layui.table,form = layui.form;
				$=layui.jquery;
				//加载表格
				table.render({
					elem:'#quartzTable',
					height:'full-100',
					page:{
						theme:'#1e9fff'
					},
					toolbar:'#tableBar',
					url:'/system/sc/find',
					cols:[
							[
						{type:'numbers',fixed:'left'},
						{type:'checkbox',fixed:'left'},
						{field:'jobName',title:'任务名称',width:120},
						{field:'jobGroup',title:'任务组名',width:120},
						{field:'className',title:'类名',width:280},
						{field:'state',title:'任务状态',width:120,templet:'#swicthState'},
						{field:'triggerName',title:'触发器名称',width:180},
						{field:'triggerGroup',title:'触发器组名',width:180},
						{field:'timeZone',title:'创建时间',width:180},
						{fixed:'right',title:'操作',width:250,align:'center',toolbar:'#tool'},
					]
					]

				})
				var active={
					openQuartz:function (title,id,did){
						var b=false;
						top.layer.open({
							type:2,
							content:'/page/system/'+did+'Quartz'+(id==""?"":"/"+id),
							title:title,
							area:['800px','700px'],
							btn:['确认保存','取消关闭'],
							btn1:function (i,o){
								b=true;
								o.find('iframe')[0].contentWindow.submitBtn();
							},
							end:function (){
								if(b) layui.table.reload('quartzTable');
							}
						})
					},
					saveQuartz:function (i,formId){
						$('#submitBtn').click();
					}
				}

				table.on('toolbar(quartzTable)',function (obj){
					var event=obj.event;

					if('add'==event){
						active.openQuartz('定时任务',"",'add');
					}
				});


				

			table.on('tool(quartzTable)',function (obj){
				var event=obj.event;
				var data=obj.data;
				if('edit'==event){
					active.openQuartz('编辑定时任务',obj.data.jobName,'edit');
				}else if('one'==event){
					$.ajax({
						type:'post',
						url:'/system/sc/runOne',
						data:data,
						dataType:'json',
						success:function (res){
							layer.msg(res.msg);
						}
					})
				}else if('delete'==event){

				}
			})

			});
		</script>
	</body>
</html>
